﻿using Newtonsoft.Json;
using PhysicalExamination5.Interface.DataMaintenance;
using PhysicalExamination5.Model.DataMaintenance;
using PhysicalExamination5.Model.PhysicalExamination;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace PhysicalExamination5.Service.DataMaintenance
{
    public class SZhenDuanJieGuoWeiHu : IZhenDuanJieGuoWeiHu
    {
        private readonly ISqlSugarClient db;
        public SZhenDuanJieGuoWeiHu(ISqlSugarClient db)
        {
            this.db = db;
        }
        /// <summary>
        /// 诊断结果维护添加
        /// </summary>
        /// <param name="JiBingAddClass"></param>
        /// <param name="strYuanQuQianZhui"></param>
        /// <returns></returns>
        public string PostJiBingAdd(JiBingAddClass JiBingAddClass, string strYuanQuQianZhui)
        {
            int nret = 0; string strFanHuiZhi = "";
            try
            {
                Logger.Singleton.Debug($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】:接收参数【{JiBingAddClass},{strYuanQuQianZhui}】");

                #region 声明变量

                int iShunXu = 0;
                int itid = 0;
                object Data = null;

                #endregion

                #region 判断是否存在相同名称的疾病

                List<jcsj_JiBing> ListJiBing = new SqlSugarRepository<jcsj_JiBing>(db).getByWhere(a => a.JiBingMingCheng == JiBingAddClass.JiBingMingCheng);

                if (ListJiBing.Count != 0)
                {
                    nret = 1;
                    strFanHuiZhi = $"当前疾病名称【{JiBingAddClass.JiBingMingCheng}】已存在！";
                    goto PROC_EXIT;
                }

                #endregion

                #region 获得顺序

                List<jcsj_JiBing> ListXinXi = new SqlSugarRepository<jcsj_JiBing>(db).getAll();

                if (ListXinXi.Count != 0)
                {
                    iShunXu = ListXinXi.Max(t => t.ShunXu) + 1;
                }
                else
                {
                    iShunXu = 1;
                }

                #endregion

                #region 执行添加数据库

                DbResult<bool> result = new SqlSugarRepository<jcsj_WeiHaiYinSuZuHeXiangMu>(db).UseTran(() =>
                {
                    jcsj_JiBing JiBing = new jcsj_JiBing();

                    JiBing.JiBingMingCheng = JiBingAddClass.JiBingMingCheng;
                    JiBing.JieShi = JiBingAddClass.JieShi;
                    JiBing.JianYi = JiBingAddClass.JianYi;
                    JiBing.ZhiDao = JiBingAddClass.ZhiDao;
                    JiBing.ChengDu = JiBingAddClass.ChengDu;
                    JiBing.PYM = JiBingAddClass.PYM;
                    JiBing.ShiYongCiShu = JiBingAddClass.ShiYongCiShu;
                    JiBing.DuiYingBuWei = JiBingAddClass.DuiYingBuWei;
                    JiBing.SuoShuYuanQu = JiBingAddClass.SuoShuYuanQu;
                    JiBing.ShunXu = iShunXu;

                    //获取到院区前缀并且加上返回来的tid
                    itid = new SqlSugarRepository<jcsj_JiBing>(db).AddReturnIdentity(JiBing);
                    JiBing.JiBingID = strYuanQuQianZhui + itid;
                    JiBing.tid = itid;

                    #region 执行修改语句将科室ID修改进去

                    if (!new SqlSugarRepository<jcsj_JiBing>(db).Update(t => new jcsj_JiBing {
                        JiBingID = JiBing.JiBingID
                    },t => t.tid == itid))
                    {
                        nret = 1;
                        strFanHuiZhi = "添加疾病失败";
                        return;
                    }

                    #endregion

                    Data = JiBing;
                },
             (ex) =>
             {
                 nret = 1000;
                 strFanHuiZhi = ex.Message;
                 Logger.Singleton.Error($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】:事务报错异常:【{ex.Message}】");
             });

            #endregion

            PROC_EXIT:
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = nret,
                    Message = strFanHuiZhi,
                    Data = Data
                });
            }
            catch (Exception ex)
            {
                Logger.Singleton.Error($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】:报错异常:" + ex.Message);
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = 1000,
                    Message = ex.Message,
                    Data = ""
                });
            }
        }
        /// <summary>
        /// 诊断结果维护修改
        /// </summary>
        /// <param name="JiBingUpdateClass"></param>
        /// <returns></returns>
        public string PutJiBingUpdate(JiBingUpdateClass JiBingUpdateClass)
        {
            int nret = 0; string strFanHuiZhi = ""; bool BolShiFouChengGong = false; string strSql = "";
            try
            {
                Logger.Singleton.Debug($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】:接收参数【{JiBingUpdateClass}】");

                
                #region 判断是否存在相同名称的疾病

                List<jcsj_JiBing> ListJiBing = new SqlSugarRepository<jcsj_JiBing>(db).getByWhere(a => a.JiBingMingCheng == JiBingUpdateClass.JiBingMingCheng && a.JiBingID != JiBingUpdateClass.JiBingID);

                if (ListJiBing.Count != 0)
                {
                    nret = 1;
                    strFanHuiZhi = $"当前疾病名称【{JiBingUpdateClass.JiBingMingCheng}】已存在！";
                    goto PROC_EXIT;
                }

                #endregion

                #region 执行修改

                strSql = $@"update jcsj_JiBing set JiBingMingCheng='{JiBingUpdateClass.JiBingMingCheng}',JieShi='{JiBingUpdateClass.JieShi}',JianYi='{JiBingUpdateClass.JianYi}',
ZhiDao='{JiBingUpdateClass.ZhiDao}',ChengDu='{JiBingUpdateClass.ChengDu}',PYM='{JiBingUpdateClass.PYM}',
ShiYongCiShu='{JiBingUpdateClass.ShiYongCiShu}',DuiYingBuWei='{JiBingUpdateClass.DuiYingBuWei}',SuoShuYuanQu='{JiBingUpdateClass.SuoShuYuanQu}'
where JiBingID='{JiBingUpdateClass.JiBingID}'
";
                BolShiFouChengGong = new SqlSugarRepository<jcsj_JiBing>(db).ExecuteCommandSql(strSql);

                if (BolShiFouChengGong == false)
                {
                    nret = 1;
                    strFanHuiZhi = "修改疾病失败，请检查";
                    goto PROC_EXIT;
                }


            #endregion


            PROC_EXIT:
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = nret,
                    Message = strFanHuiZhi,
                    Data = ""
                });
            }
            catch (Exception ex)
            {
                Logger.Singleton.Error($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】:报错异常:" + ex.Message);
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = 1000,
                    Message = ex.Message,
                    Data = ""
                });
            }
        }
        /// <summary>
        /// 根据疾病名称查询
        /// </summary>
        /// <param name="strJiBingMingCheng"></param>
        /// <param name="strShiFouWanQuanPiPei"></param>
        /// <param name="YuanQu"></param>
        /// <returns></returns>
        public string GetJiBingSel(string strJiBingMingCheng, string strShiFouWanQuanPiPei, string YuanQu, int intPage, int intPageSize)
        {
            int nret = 0; string strFanHuiZhi = ""; List<jcsj_JiBing> ListJiBing = new List<jcsj_JiBing>(); int intPageCount = 0;
            Expression<Func<jcsj_JiBing, bool>> FunJiBingWhere = null;
            try
            {
                Logger.Singleton.Debug($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】:接收参数【{strJiBingMingCheng},{strShiFouWanQuanPiPei}】");

                #region 数据校验

                if (string.IsNullOrEmpty(strJiBingMingCheng))
                {
                    nret = 1;
                    strFanHuiZhi = "疾病名称为空，请检查！";
                    goto PROC_EXIT;
                }

                #endregion

                #region 执行查询

                if (strShiFouWanQuanPiPei == "是")
                {

                    FunJiBingWhere = t => t.JiBingMingCheng == strJiBingMingCheng || t.PYM == strJiBingMingCheng && t.SuoShuYuanQu.Contains(YuanQu);
                }
                else
                {
                    FunJiBingWhere = t => t.JiBingMingCheng.Contains(strJiBingMingCheng) || t.PYM.Contains(strJiBingMingCheng) && t.SuoShuYuanQu.Contains(YuanQu);
                }

                #endregion

                //单表分页
                intPageCount = new SqlSugarRepository<jcsj_JiBing>(db).getByWhere(FunJiBingWhere).Count();
                ListJiBing = new SqlSugarRepository<jcsj_JiBing>(db).getPageList(intPage, intPageSize, true, FunJiBingWhere, true, A => A.ShunXu, OrderByType.Asc);

            PROC_EXIT:
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = nret,
                    Message = strFanHuiZhi,
                    Data = new
                    {
                        pageCount = intPageCount,
                        ListXinXi = ListJiBing
                    }
                });
            }
            catch (Exception ex)
            {
                Logger.Singleton.Error($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】:报错异常:" + ex.Message);
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = 1000,
                    Message = ex.Message,
                    Data = ""
                });
            }
        }
        /// <summary>
        /// 疾病通用名添加
        /// </summary>
        /// <param name="strTongYongMingMingCheng"></param>
        /// <param name="strYuanQuQianZhui"></param>
        /// <returns></returns>
        public string PostTongYongMingAdd(JiBingTongYongMingAddClass JiBingTongYongMingAddClass, string strYuanQuQianZhui)
        {
            int nret = 0; string strFanHuiZhi = "";
            try
            {
                Logger.Singleton.Debug($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】:接收参数【{JiBingTongYongMingAddClass.TongYongMingMingCheng}】");

                #region 声明变量

                object Data = null;
                int itid = 0;

                #endregion

                #region 判断是否存在相同名称的疾病通用名

                List<jcsj_TongYongMing> ListTongYongMing = new SqlSugarRepository<jcsj_TongYongMing>(db).getByWhere(a => a.TongYongMingMingCheng == JiBingTongYongMingAddClass.TongYongMingMingCheng);

                if (ListTongYongMing.Count != 0)
                {
                    nret = 1;
                    strFanHuiZhi = $"当前疾病通用名【{JiBingTongYongMingAddClass.TongYongMingMingCheng}】已存在！";
                    goto PROC_EXIT;
                }

                #endregion

                #region 执行新增操作

                DbResult<bool> result = new SqlSugarRepository<jcsj_WeiHaiYinSuZuHeXiangMu>(db).UseTran(() =>
                {

                    jcsj_TongYongMing TongYongMing = new jcsj_TongYongMing();

                    TongYongMing.TongYongMingMingCheng = JiBingTongYongMingAddClass.TongYongMingMingCheng;


                    //获取到院区前缀并且加上返回来的tid
                    itid = new SqlSugarRepository<jcsj_TongYongMing>(db).AddReturnIdentity(TongYongMing);
                    TongYongMing.TongYongMingID = strYuanQuQianZhui + itid;
                    TongYongMing.tid = itid;

                    #region 执行修改语句将科室ID修改进去

                    if (!new SqlSugarRepository<jcsj_TongYongMing>(db).Update(t => new jcsj_TongYongMing
                    {
                        TongYongMingID = TongYongMing.TongYongMingID
                    },t => t.tid == itid))
                    {
                        nret = 1;
                        strFanHuiZhi = "添加失败！";
                        return;
                    }
                    Data = TongYongMing;

                    #endregion
                },
                 (ex) =>
                 {
                     nret = 1000;
                     strFanHuiZhi = ex.Message;
                     Logger.Singleton.Error($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】:事务报错异常:【{ex.Message}】");
                 });

                #endregion


            PROC_EXIT:
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = nret,
                    Message = strFanHuiZhi,
                    Data = ""
                });
            }
            catch (Exception ex)
            {
                Logger.Singleton.Error($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】:报错异常:" + ex.Message);
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = 1000,
                    Message = ex.Message,
                    Data = ""
                });
            }
        }
        /// <summary>
        /// 疾病通用名修改
        /// </summary>
        /// <param name="strTongYongMingID"></param>
        /// <param name="strTongYongMing"></param>
        /// <returns></returns>
        public string PutTongYongMingUpdate(JiBingTongYongMingUpdateClass JiBingTongYongMingUpdateClass)
        {
            int nret = 0; string strFanHuiZhi = ""; bool BolShiFouChengGong = false; string strSql = "";
            try
            {
                Logger.Singleton.Debug($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】:接收参数【{JiBingTongYongMingUpdateClass.TongYongMingID}】");

                
                #region 判断是否存在相同名称的通用名

                List<jcsj_TongYongMing> ListTongYongMing = new SqlSugarRepository<jcsj_TongYongMing>(db).getByWhere(a => a.TongYongMingMingCheng == JiBingTongYongMingUpdateClass.TongYongMingMingCheng && a.TongYongMingID != JiBingTongYongMingUpdateClass.TongYongMingID);

                if (ListTongYongMing.Count != 0)
                {
                    nret = 1;
                    strFanHuiZhi = $"当前疾病通用名【{JiBingTongYongMingUpdateClass.TongYongMingMingCheng}】已存在！";
                    goto PROC_EXIT;
                }

                #endregion

                #region 执行修改操作

                BolShiFouChengGong = new SqlSugarRepository<jcsj_TongYongMing>(db).Update(t => new jcsj_TongYongMing
                {
                    TongYongMingMingCheng = JiBingTongYongMingUpdateClass.TongYongMingMingCheng

                }, t => t.TongYongMingID == JiBingTongYongMingUpdateClass.TongYongMingID);

                if (BolShiFouChengGong == false)
                {
                    nret = 1;
                    strFanHuiZhi = "修改疾病通用名失败，请检查！";
                    goto PROC_EXIT;
                }

            #endregion



            PROC_EXIT:
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = nret,
                    Message = strFanHuiZhi,
                    Data = ""
                });
            }
            catch (Exception ex)
            {
                Logger.Singleton.Error($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】:报错异常:" + ex.Message);
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = 1000,
                    Message = ex.Message,
                    Data = ""
                });
            }
        }
        /// <summary>
        /// 疾病通用名删除
        /// </summary>
        /// <param name="strTongYongMingID"></param>
        /// <returns></returns>
        public string DeleteTongYongMingDel(JiBingTongYongMingDelClass JiBingTongYongMingDelClass)
        {
            int nret = 0; string strFanHuiZhi = "";
            bool BolShiFouChengGong = false;
            try
            {
                Logger.Singleton.Debug($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】接受参数：【{JiBingTongYongMingDelClass.TongYongMingID}】");

                #region 执行删除

                BolShiFouChengGong = new SqlSugarRepository<jcsj_TongYongMing>(db).DeleteWhere(A => A.TongYongMingID == JiBingTongYongMingDelClass.TongYongMingID);

                if (BolShiFouChengGong == false)
                {
                    nret = 1;
                    strFanHuiZhi = "删除疾病通用名失败，请检查！";
                    goto PROC_EXIT;
                }

            #endregion


            PROC_EXIT:
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = nret,
                    Message = strFanHuiZhi,
                    Data = ""

                });
            }
            catch (Exception ex)
            {
                Logger.Singleton.Error($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】:报错异常:" + ex.Message);
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = 1000,
                    Message = ex.Message,
                    Data = ""
                });
            }
        }
        /// <summary>
        /// 根据通用名查询疾病通用名
        /// </summary>
        /// <param name="strTongYongMing"></param>
        /// <returns></returns>
        public string GetTongYongMingSel(string strTongYongMing)
        {
            int nret = 0; string strFanHuiZhi = ""; List<jcsj_TongYongMing> ListTongYongMing = new List<jcsj_TongYongMing>();
            try
            {
                Logger.Singleton.Debug($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】接受参数：【{strTongYongMing}】");

                #region 执行查询

                ListTongYongMing = new SqlSugarRepository<jcsj_TongYongMing>(db).getAll()
                       .Where(t => t.TongYongMingMingCheng.Contains(strTongYongMing))
                       .ToList();

                #endregion


            PROC_EXIT:
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = nret,
                    Message = strFanHuiZhi,
                    Data = ListTongYongMing

                });
            }
            catch (Exception ex)
            {
                Logger.Singleton.Error($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】:报错异常:" + ex.Message);
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = 1000,
                    Message = ex.Message,
                    Data = ""
                });
            }
        }
        /// <summary>
        /// 增加疾病对应通用名
        /// </summary>
        /// <param name="strTongYongMingID"></param>
        /// <param name="strJiBingID"></param>
        /// <returns></returns>
        public string PostJiBingDuiYingTongYongMing(JiBingDuiYingTongYongMingAddClass JiBingDuiYingTongYongMingAddClass)
        {
            int nret = 0; string strFanHuiZhi = "";
            try
            {
                Logger.Singleton.Debug($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】接受参数：【{JiBingDuiYingTongYongMingAddClass.TongYongMingID},{JiBingDuiYingTongYongMingAddClass.JiBingID}】");

                object Data = null;
                string strSql = "";

                #region 执行插入

                jcsj_TongYongMingDuiYingJiBing TongYongMingDuiYingJiBing = new jcsj_TongYongMingDuiYingJiBing();

                TongYongMingDuiYingJiBing.TongYongMingID = JiBingDuiYingTongYongMingAddClass.TongYongMingID;
                TongYongMingDuiYingJiBing.JiBingID = JiBingDuiYingTongYongMingAddClass.JiBingID;

                if (!new SqlSugarRepository<jcsj_TongYongMingDuiYingJiBing>(db).Add(TongYongMingDuiYingJiBing))
                {
                    nret = 1;
                    strFanHuiZhi = "添加通用名对应疾病出现错误，请检查！";
                    goto PROC_EXIT;
                }

                #endregion

                strSql = $@"select B.JiBingMingCheng,B.JiBingID from jcsj_TongYongMingDuiYingJiBing A, jcsj_JiBing B
with(nolock) where A.JiBingID= B.JiBingID and A.TongYongMingID = '{JiBingDuiYingTongYongMingAddClass.TongYongMingID}' and JiBingID = '{JiBingDuiYingTongYongMingAddClass.JiBingID}'";
                Data = new SqlSugarRepository<object>(db).getListBySql(strSql);



            PROC_EXIT:
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = nret,
                    Message = strFanHuiZhi,
                    Data = Data

                });
            }
            catch (Exception ex)
            {
                Logger.Singleton.Error($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】:报错异常:" + ex.Message);
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = 1000,
                    Message = ex.Message,
                    Data = ""
                });
            }
        }
        /// <summary>
        /// 根据通用名ID查询通用名疾病
        /// </summary>
        /// <param name="strTongYongMingID"></param>
        /// <returns></returns>
        public string GetTongYongMingJiBingSel(string strTongYongMingID)
        {
            int nret = 0; string strFanHuiZhi = ""; List<object> ListTongYongMingJiBing = new List<object>();
            string strSql = "";
            try
            {
                Logger.Singleton.Debug($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】接受参数：【{strTongYongMingID}】");

                #region 执行查询

                strSql = $@"select B.JiBingMingCheng,B.JiBingID from jcsj_TongYongMingDuiYingJiBing A, jcsj_JiBing B
with(nolock) where A.JiBingID= B.JiBingID and A.TongYongMingID = '{strTongYongMingID}'";
                ListTongYongMingJiBing = new SqlSugarRepository<object>(db).getListBySql(strSql);

            #endregion

            PROC_EXIT:
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = nret,
                    Message = strFanHuiZhi,
                    Data = ListTongYongMingJiBing

                });
            }
            catch (Exception ex)
            {
                Logger.Singleton.Error($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】:报错异常:" + ex.Message);
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = 1000,
                    Message = ex.Message,
                    Data = ""
                });
            }
        }
        /// <summary>
        /// 根据疾病ID删除疾病信息
        /// </summary>
        /// <param name="strJiBingID"></param>
        /// <returns></returns>
        public string DeleteJiBingDel(JiBingDelClass JiBingDelClass)
        {
            int nret = 0; string strFanHuiZhi = "";
            bool BolShiFouChengGong = false;
            try
            {
                Logger.Singleton.Debug($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】接受参数：【{JiBingDelClass.JiBingID}】");

                #region 执行删除

                BolShiFouChengGong = new SqlSugarRepository<jcsj_JiBing>(db).DeleteWhere(A => A.JiBingID == JiBingDelClass.JiBingID);

                if (BolShiFouChengGong == false)
                {
                    nret = 1;
                    strFanHuiZhi = "删除疾病失败，请检查！";
                    goto PROC_EXIT;
                }

            #endregion


            PROC_EXIT:
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = nret,
                    Message = strFanHuiZhi,
                    Data = ""

                });
            }
            catch (Exception ex)
            {
                Logger.Singleton.Error($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】:报错异常:" + ex.Message);
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = 1000,
                    Message = ex.Message,
                    Data = ""
                });
            }
        }
        /// <summary>
        /// 根据疾病ID查询疾病包含关键字
        /// </summary>
        /// <param name="strJiBingID"></param>
        /// <returns></returns>
        public string GetSelJiBingBaoHanGuanJianZi(string strJiBingID)
        {
            int nret = 0; string strFanHuiZhi = "";
            try
            {
                Logger.Singleton.Debug($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】");

                List<jcsj_JiBingBaoHanGuanJianZi> listjcsj_JiBingBaoHanGuanJianZi = new SqlSugarRepository<jcsj_JiBingBaoHanGuanJianZi>(db).getByWhere(t => t.JiBingID == strJiBingID);


            PROC_EXIT:
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = nret,
                    Message = strFanHuiZhi,
                    Data = listjcsj_JiBingBaoHanGuanJianZi
                });
            }
            catch (Exception ex)
            {
                Logger.Singleton.Error($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】:报错异常:" + ex.Message);
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = 1000,
                    Message = ex.Message,
                    Data = ""
                });
            }
        }
        /// <summary>
        /// 疾病包含关键字添加
        /// </summary>
        /// <param name="strJiBingID"></param>
        /// <param name="strGuanJianZiMingCheng"></param>
        /// <returns></returns>
        public string PostJiBingBaoHanGuanJianZiAdd(JiBingBaoHanGuanJianZiAddClass JiBingBaoHanGuanJianZiAddClass)
        {
            int nret = 0; string strFanHuiZhi = "";
            try
            {
                Logger.Singleton.Debug($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】接受参数：【{JiBingBaoHanGuanJianZiAddClass}】");

                #region 声明变量

                object Data = null;

                #endregion

                #region 判断是否存在相同名称的疾病通用名

                List<jcsj_JiBingBaoHanGuanJianZi> ListJiBingBaoHanGuanJianZi = new SqlSugarRepository<jcsj_JiBingBaoHanGuanJianZi>(db)
                    .getByWhere(a => a.GuanJianZi == JiBingBaoHanGuanJianZiAddClass.GuanJianZi && a.JiBingID == JiBingBaoHanGuanJianZiAddClass.JiBingID);

                if (ListJiBingBaoHanGuanJianZi.Count != 0)
                {
                    nret = 1;
                    strFanHuiZhi = $"当前疾病关键字【{JiBingBaoHanGuanJianZiAddClass.GuanJianZi}】已存在！";
                    goto PROC_EXIT;
                }

                #endregion

                #region 执行添加

                jcsj_JiBingBaoHanGuanJianZi JiBingBaoHanGuanJianZi = new jcsj_JiBingBaoHanGuanJianZi();

                JiBingBaoHanGuanJianZi.JiBingID = JiBingBaoHanGuanJianZiAddClass.JiBingID;
                JiBingBaoHanGuanJianZi.GuanJianZi = JiBingBaoHanGuanJianZiAddClass.GuanJianZi;

                Data = new SqlSugarRepository<jcsj_JiBingBaoHanGuanJianZi>(db).AddReturnEntity(JiBingBaoHanGuanJianZi);
                

            #endregion

            PROC_EXIT:
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = nret,
                    Message = strFanHuiZhi,
                    Data = Data

                });
            }
            catch (Exception ex)
            {
                Logger.Singleton.Error($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】:报错异常:" + ex.Message);
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = 1000,
                    Message = ex.Message,
                    Data = ""
                });
            }
        }
        /// <summary>
        /// 疾病包含关键字修改
        /// </summary>
        /// <param name="strJiBingID"></param>
        /// <param name="strGuanJianZiMingCheng"></param>
        /// <returns></returns>
        public string PutJiBingBaoHanGuanJianZiUpdate(JiBingBaoHanGuanJianZiUpdateClass JiBingBaoHanGuanJianZiUpdateClass)
        {
            int nret = 0; string strFanHuiZhi = "";
            bool BolShiFouChengGong = false;
            try
            {
                Logger.Singleton.Debug($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】接受参数：【{JiBingBaoHanGuanJianZiUpdateClass}】");

                #region 判断是否存在

                List<jcsj_JiBingBaoHanGuanJianZi> ListJiBingBaoHanGuanJianZi = new SqlSugarRepository<jcsj_JiBingBaoHanGuanJianZi>(db)
                    .getByWhere(a => a.GuanJianZi == JiBingBaoHanGuanJianZiUpdateClass.GuanJianZi && a.tid != JiBingBaoHanGuanJianZiUpdateClass.iTid);

                if (ListJiBingBaoHanGuanJianZi.Count != 0)
                {
                    nret = 1;
                    strFanHuiZhi = $"当前疾病关键字【{JiBingBaoHanGuanJianZiUpdateClass.GuanJianZi}】已存在！";
                    goto PROC_EXIT;
                }

                #endregion

                #region 执行修改


                string strSql = $@"update jcsj_JiBingBaoHanGuanJianZi set GuanJianZi = '{JiBingBaoHanGuanJianZiUpdateClass.GuanJianZi}'
where tid = '{JiBingBaoHanGuanJianZiUpdateClass.iTid}'";

                if (!new SqlSugarRepository<object>(db).ExecuteCommandSql(strSql))
                {
                    nret = 1;
                    strFanHuiZhi = "修改疾病包含关键字失败，请检查！";
                    goto PROC_EXIT;
                }

               /* BolShiFouChengGong = new SqlSugarRepository<jcsj_JiBingBaoHanGuanJianZi>(db).Update(t => new jcsj_JiBingBaoHanGuanJianZi
                {
                    GuanJianZi = JiBingBaoHanGuanJianZiUpdateClass.GuanJianZi

                }, t => t.JiBingID == JiBingBaoHanGuanJianZiUpdateClass.JiBingID);

                if (BolShiFouChengGong == false)
                {
                    nret = 1;
                    strFanHuiZhi = "修改疾病包含关键字失败，请检查！";
                    goto PROC_EXIT;
                }*/

            #endregion


            PROC_EXIT:
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = nret,
                    Message = strFanHuiZhi,
                    Data = ""

                });
            }
            catch (Exception ex)
            {
                Logger.Singleton.Error($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】:报错异常:" + ex.Message);
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = 1000,
                    Message = ex.Message,
                    Data = ""
                });
            }
        }
        /// <summary>
        /// 疾病包含关键字删除
        /// </summary>
        /// <param name="JiBingBaoHanGuanJianZiDelClass"></param>
        /// <returns></returns>
        public string DelJiBingBaoHanGuanJianZiDelete(JiBingBaoHanGuanJianZiDelClass JiBingBaoHanGuanJianZiDelClass)
        {
            int nret = 0; string strFanHuiZhi = "";
            bool BolShiFouChengGong = false;
            try
            {
                Logger.Singleton.Debug($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】接受参数：【{JiBingBaoHanGuanJianZiDelClass}】");

              
                #region 执行删除

                BolShiFouChengGong = new SqlSugarRepository<jcsj_JiBingBaoHanGuanJianZi>(db).DeleteWhere(A => A.tid == JiBingBaoHanGuanJianZiDelClass.iTid);

                if (BolShiFouChengGong == false)
                {
                    nret = 1;
                    strFanHuiZhi = "删除疾病包含关键字失败，请检查！";
                    goto PROC_EXIT;
                }

            #endregion


            PROC_EXIT:
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = nret,
                    Message = strFanHuiZhi,
                    Data = ""

                });
            }
            catch (Exception ex)
            {
                Logger.Singleton.Error($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】:报错异常:" + ex.Message);
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = 1000,
                    Message = ex.Message,
                    Data = ""
                });
            }
        }
        /// <summary>
        /// 疾病对应通用名删除
        /// </summary>
        /// <param name="JiBingDuiYingTongYongMingDelClass"></param>
        /// <returns></returns>
        public string DelJiBingDuiYingTongYongMingDelete(JiBingDuiYingTongYongMingDelClass JiBingDuiYingTongYongMingDelClass)
        {
            int nret = 0; string strFanHuiZhi = "";
            bool BolShiFouChengGong = false;
            try
            {
                Logger.Singleton.Debug($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】接受参数：【{JiBingDuiYingTongYongMingDelClass}】");

                #region 数据校验

                if (string.IsNullOrEmpty(JiBingDuiYingTongYongMingDelClass.TongYongMingID))
                {
                    nret = 1;
                    strFanHuiZhi = "通用名ID为空,请检查！";
                    goto PROC_EXIT;
                }

                if (string.IsNullOrEmpty(JiBingDuiYingTongYongMingDelClass.JiBingID))
                {
                    nret = 1;
                    strFanHuiZhi = "疾病ID为空,请检查！";
                    goto PROC_EXIT;
                }

                #endregion

                #region 执行删除

                BolShiFouChengGong = new SqlSugarRepository<jcsj_TongYongMingDuiYingJiBing>(db).DeleteWhere(A => A.JiBingID == JiBingDuiYingTongYongMingDelClass.JiBingID && A.TongYongMingID == JiBingDuiYingTongYongMingDelClass.TongYongMingID);

                if (BolShiFouChengGong == false)
                {
                    nret = 1;
                    strFanHuiZhi = "删除疾病对应通用名失败，请检查！";
                    goto PROC_EXIT;
                }

            #endregion


            PROC_EXIT:
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = nret,
                    Message = strFanHuiZhi,
                    Data = ""

                });
            }
            catch (Exception ex)
            {
                Logger.Singleton.Error($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】:报错异常:" + ex.Message);
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = 1000,
                    Message = ex.Message,
                    Data = ""
                });
            }
        }
    }
}
